﻿using SimpleInjector;
using Sustainalytics.Claims;
using Sustainalytics.ClientDW.DataAccessLayer;
using Sustainalytics.ClientDW.Entities;
using Sustainalytics.DataLayer;
using Sustainalytics.DataLayer.Shared;
using Sustainalytics.Entities;
using Sustainalytics.Entities.SustainableProducts;
using Sustainalytics.MongoDB.Extensions;
using System.Configuration;
using System.Web.Http;

namespace Sustainalytics.SustainableProducts.Service.Infrastructure
{
    public static class CompositionRoot
    {
       
        public static Container RegisterDependencies(HttpConfiguration config)
        {
            var container = new Container();

            container.Options.DefaultScopedLifestyle = new SimpleInjector.Lifestyles.AsyncScopedLifestyle();
            container.RegisterWebApiControllers(config);

            container.RegisterMisc();
            
            container.RegisterCollections();

            container.Verify();
            
            return container; 
        }

        private static void RegisterCollections(this Container container)
        {
            container.Register(() => MongoFactory.GetCollectionFromDatabase<CorporateData>(MongoFactory.GetConnectionStrings().ClientDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<SustainableProductsData>(MongoFactory.GetConnectionStrings().ProductInvolvementDW));
            container.Register(() => MongoFactory.GetCollectionFromDatabase<SustainableProductsFramework>(MongoFactory.GetConnectionStrings().ProductInvolvementDW));
            container.Register(() => MongoFactory.GetCollectionFromClientPlatform<TemplateCriteria>());
        }

        private static void RegisterMisc(this Container container)
        {
            container.Register(() => MongoFactory.GetConnectionStrings());
            container.RegisterSingleton(typeof(IClaimsChecker), () => new ClaimsChecker());
        }
    }
  }




